﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ATM
{
    public class ChooseTransactionState : ATMState
    {
        public ATM atm;

        public ChooseTransactionState(ATM atm)
        {
            this.atm = atm;
        }

        public void pressPowerButton()
        {
            return;
        }

        public void pressTakeCashButton()
        {
            return;
        }

        public void pressInsertEnvelopButton()
        {
            return;
        }

        public void pressEnterButton()
        {
            if (this.atm.keypadScreen.Text == "")
            {
                System.Windows.Forms.MessageBox.Show("请输入数字后按Enter键确认!");
                return;
            }

            this.atm.commandString = this.atm.keypadScreen.Text;
            this.atm.commandNumber = Convert.ToInt32(this.atm.commandString);
            this.atm.keypadScreen.Text = "";

            switch (this.atm.commandNumber)
            {
                case 1:
                    this.atm.screen.Text = "请输入取款金额：";
                    this.atm.setState(this.atm.inputWithdrawAmountState);
                    break;
                case 2:
                    this.atm.setState(this.atm.balanceInquiryState);
                    this.atm.balanceInquiry.account = this.atm.currentAccountID;
                    this.atm.screen.Text = "正在查询...\r\n\r\n";
                    this.atm.screen.Text += "您的余额是:";
                    this.atm.screen.Text += (this.atm.bankDatabase.balanceInquiry(this.atm.balanceInquiry.account)).ToString();
                    this.atm.screen.Text += "\r\n\r\n";
                    this.atm.screen.Text += "请选择下一步操作:\r\n";
                    this.atm.screen.Text += "1、继续业务\r\n";
                    this.atm.screen.Text += "2、打印凭条";
                    this.atm.receipt.receiptDetails = "账号:" + this.atm.balanceInquiry.account + "\r\n" +
                        "业务类型:查询余额\r\n" + "账户余额:" + (this.atm.bankDatabase.balanceInquiry(this.atm.balanceInquiry.account)).ToString();
                    this.atm.log.addLog(this.atm.receipt.receiptDetails);
                        break;
                case 3:
                    this.atm.setState(this.atm.transferAccountState1);
                    this.atm.screen.Text = "请输入要转账的金额";
                    this.atm.transferAccounts.account = this.atm.currentAccountID;
                    break;

                case 4:
                    this.atm.setState(this.atm.insertEnvelopState);
                    this.atm.insertEnvelopButton.Enabled = true;
                    this.atm.enterButton.Enabled = false;
                    this.atm.screen.Text = "请放入存款信封：";
                    break;

                case 5:
                    this.atm.setState(this.atm.powerOnState);
                    this.atm.switchButton.Enabled = true;
                    this.atm.screen.Text = "欢迎使用ATM模拟系统!";
                    this.atm.screen.Text += "\r\n\r\n";
                    this.atm.screen.Text += "请输入银行卡号登录!";
                    break;

                default:
                    System.Windows.Forms.MessageBox.Show("错误的选项!请重新选择");
                    break;
            }

            return;
        }
    }
}
